#!/bin/bash

# Define current run.
target=/data2/projects/huref_scaffold/bowtie_idxs/hs_alt_random_contigs_color_idx
reference=/data2/projects/huref_scaffold/assemblies/hs_alt_random_contigs.fasta

query1=/data2/reads/solid/venter_genome/venter_R3.csfasta
query2=/data2/reads/solid/venter_genome/venter_F3.csfasta

output1=/data2/projects/huref_scaffold/maps/reads_complete/venter_R3.sam
output1a=/data2/projects/huref_scaffold/maps/reads_complete/venter_R3.tmp
output1b=/data2/projects/huref_scaffold/maps/reads_complete/venter_R3.namesorted
output1c=/data2/projects/huref_scaffold/maps/reads_complete/venter_R3.possorted

output2=/data2/projects/huref_scaffold/maps/reads_complete/venter_F3.sam
output2a=/data2/projects/huref_scaffold/maps/reads_complete/venter_F3.tmp
output2b=/data2/projects/huref_scaffold/maps/reads_complete/venter_F3.namesorted
output2c=/data2/projects/huref_scaffold/maps/reads_complete/venter_F3.possorted

maxoutput1=/data2/projects/huref_scaffold/maps/reads_complete/venter_R3_repeats.fasta
maxoutput2=/data2/projects/huref_scaffold/maps/reads_complete/venter_F3_repeats.fasta

# Launch first in subshell.
(
bowtie --sam --max $maxoutput1 -p 20 -f -C -n 2 -e 160 -m 20 $target $query1 $output1 
samtools view -bt $reference $output1 -o $output1a
samtools sort -n -m 500000000000 $output1a $output1b
samtools sort -m 500000000000 $output1a $output1c
samtools index $output1b.bam
samtools index $output1c.bam
rm $output1a
) &

# Launch second in subshell.
(
bowtie --sam --max $maxoutput2 -p 20 -f -C -n 2 -e 160 -m 20 $target $query2 $output2 
samtools view -bt $reference $output2 -o $output2a
samtools sort -n -m 500000000000 $output2a $output2b
samtools sort -m 500000000000 $output2a $output2c
samtools index $output2b.bam
samtools index $output2c.bam
rm $output2a
) &
